<?php
/**
*
* 功能描述（短信逻辑）
*
* @author suoya <jlusuoya@gmail.com>
* @version 1
*/

class ModelMobile extends ModelBase
{
	function CheckAuthcode($mobile, $auth_code, &$obj)
	{
		$ret = 0;
		if($obj['cnt'] <= 0 || $obj['lastSend'] + 60 < time(0))
		{
			$obj = "";
			$ret = 4;
		}
		else if($obj['code'] != $auth_code)
			$ret = 1;
		else if($obj['mobile'] != $mobile)
			$ret = 3;
		if($obj != "")
			$obj['cnt']--;		//次数减一
		return $ret;
	}

	function SendAuthcode($mobile, &$obj, $opmsg)
	{
		if($obj == '')
			$obj = array('code' =>0, 'lastSend' => 0, 'mobile'=>0, 'cnt' => 0);
		$curTime = time(0);
		if($obj['lastSend'] + 6 > $curTime)
			return 0;
		srand($curTime);
		$auth = rand(100000,999999);
		$obj['code'] = $auth;
		$obj['lastSend'] = $curTime;
		$obj['mobile'] = $mobile;
		$obj['cnt'] = 10;			// 限操作10次
		$msg;
		SendMobileMsg($msg, array($mobile), '您本次'.$opmsg.'验证码为'.$auth);
		return $obj;
	}
}

